/**
 * *出版社对账单中：选择单据按钮事件
 */
function cwSureAddCBSItem(){
	// 获取供应商
	var PUB_ID=$('#pres_addWinTable').find('input[qucln=PUB_ID]').val();

	if (PUB_ID==''){
		$.messager.alert('提示','请选择出版社！');
		return;
	}
    //如果修改供应商，则清空明细的数据
    $("#pres_addWinForm input[qucln='PUB_ID']").change(function(){
        $('#pres_addItemDatagrid').datagrid('loadData',{total:0,rows:[]});
    });
	_data_qw('press','ds_cw_press_item2','press_sure1','44','clowQuery','');
}

//选择单据弹出窗口的回调函数
function clowQuery(){
	$('#press_dataQuery').attr('onclick','cbsjsQuery(this)');
}

//出版社对账单的选择单据的查询按钮
function cbsjsQuery(obj){
	var prefix=$(obj).attr('pre');
	var dsId=$(obj).attr('dsid');
	var resultDG = 'DATA_DATALIST';
	var comUseConf='commUseD';
	var PUB_ID=$('#pres_addWinTable').find('input[qucln=PUB_ID]').val();
	var otherConfig = "1-PUB_ID-"+PUB_ID+"-inc|+";
	var comUse = parseConfig(prefix+"_"+comUseConf);
	var useConf = otherConfig+comUse;
	
	//获取对账明细的数据行
	var dzmxRows = $('#pres_addItemDatagrid').datagrid('getRows');
	var ids='';
	if(dzmxRows.length>0){
		for(var i=0,j=dzmxRows.length;i<j;i++){
			ids+="'"+dzmxRows[i].I_INFO+"',";
		}
		ids=ids.substring(0,ids.lastIndexOf(","));
		ids=" and I_INFO not in("+ids+")";
	}
	//将YW_ID组成一个'YW_ID',字符串
	//将datagrid 获取到后 就用变量存起来,不然每次 jquery 获取都是一次耗时操作
	var queryDG=$('#'+prefix+"_"+resultDG);
	queryDG.datagrid({
			idField:"I_INFO",
			pageNumber:1,
			pagination:true,
			pageList:[300],
			url:_m_url+'framework/loadDataQ',
			queryParams:{'dsId':dsId,'config':useConf,"originalSql":ids}
	});
}

/**
 * 弹窗的确定按钮
 * 
 * @return
 */
function press_sure1(){
	// 关闭弹窗
	$('#press_DATA_PARENT_PANEL').window('close');
	// 原有明细数据
	var oldRows = $('#pres_addItemDatagrid').datagrid('getRows');
	// 获取选择的数据
	var selRows = $('#press_DATA_DATALIST').datagrid('getSelections');
	
	// 关闭弹出窗口的editor
	for(var i=0;i<selRows.length;i++){
		var index=$('#press_DATA_DATALIST').datagrid("getRowIndex",selRows[i]);
		$('#press_DATA_DATALIST').datagrid('endEdit',index);
	}
	var amount;
	var price;
	for ( var j = 0; j < selRows.length; j++) {
		$('#pres_addItemDatagrid').datagrid('appendRow', {
            VERIFY_DATE:selRows[j].VERIFY_DATE,
            DJ_CODE:selRows[j].DJ_CODE,
			DJ_TYPE:selRows[j].DJ_TYPE,
            XT_ID:selRows[j].XT_ID,
            YINCI:selRows[j].YINCI,
            KAIBEN:selRows[j].KAIBEN,
            H_PRICE:selRows[j].H_PRICE,
            YINSHU:selRows[j].YINSHU,
            RUKUSHU:selRows[j].RUKUSHU,
			REAL_MONEY:selRows[j].REAL_MONEY,
            JIAFANG:selRows[j].JIAFANG,
			I_INFO:selRows[j].I_INFO
		});
	}
}

/**
 * 出版社对账单的删除明细的按钮
 */
function itemRowDelCcb(obj,dgUrl,queryParams){
    // 获取选中的行
    var oldRows = $('#pres_addItemDatagrid').datagrid('getSelections');
    if(oldRows.length == 0){
        $.messager.alert("操作提示","请选择一条记录,再进行删除！","info");
        return;
    }
    for(var i =0;i<oldRows.length;i++){
        var rowIndex= $('#pres_addItemDatagrid').datagrid('getRowIndex',oldRows[i]);
        $('#pres_addItemDatagrid').datagrid('deleteRow',rowIndex);
    }
}



